#include "ExploreScreen.h"
#include "BaseGame.h"
#include "AudioManager.h"
ExploreScreen::ExploreScreen(hgeFont* font,GameData* gameData) :BaseScreen(font, gameData)
{
	HTEXTURE tex = g_pHge->Texture_Load("Content/up.png");
	HTEXTURE tex2 = g_pHge->Texture_Load("Content/down.png");
	HTEXTURE tex3 = g_pHge->Texture_Load("Content/button_explore.png");
	HTEXTURE tex4 = g_pHge->Texture_Load("Content/ExploreScreen.png");

	m_sprite = new hgeSprite(tex4, 0,0,g_pHge->Texture_GetWidth(tex4), g_pHge->Texture_GetHeight(tex4));

	m_helperExploreTextPos = hgeVector(180,300);
	m_pAddHelperButtonUp	=		new hgeGUIButton(1, m_helperExploreTextPos.x - 30,m_helperExploreTextPos.y - 8,16,16,tex,0,0);
	m_pAddHelperButtonDown	=		new hgeGUIButton(2, m_helperExploreTextPos.x - 30,m_helperExploreTextPos.y + 8,16,16,tex2,0,0);
	
	m_timeTextPos = hgeVector(180, 340);
	m_pAddTimeButtonUp		=		new hgeGUIButton(3, m_timeTextPos.x - 30,m_timeTextPos.y - 8,16,16,tex,0,0);
	m_pAddTimeButtonDown	=		new hgeGUIButton(4, m_timeTextPos.x - 30,m_timeTextPos.y + 8,16,16,tex2,0,0);
	
	
	m_pSubmit =	new hgeGUIButton(5, 180,370,128,32,tex3,0,0);

	hGui = new hgeGUI();
	hGui->Enter();
	hGui->AddCtrl(m_pAddHelperButtonUp);
	hGui->AddCtrl(m_pAddHelperButtonDown);
	hGui->AddCtrl(m_pAddTimeButtonUp);
	hGui->AddCtrl(m_pAddTimeButtonDown);

	hGui->AddCtrl(m_pSubmit);

	guiId = m_preHelperChoice=0;
	m_timeAssigned=1.0f;
	textSpace = 20;
	m_candyCaneModifier = 2;
}


ExploreScreen::~ExploreScreen(void)
{
}

void ExploreScreen::Render()
{
	m_sprite->RenderStretch(143,0,800,460);
	pFont->SetColor( ARGB(255,0,0,0));
	pFont->SetScale(2.5f);

	pFont->printf(300,10,HGETEXT_LEFT, "Explore");
	pFont->SetScale(0.6f);
	//pFont->printf(300,70,HGETEXT_LEFT, "Total Helpers %i", pGameData->HelpersWorking + pGameData->HelpersAvailable + pGameData->HelpersWorking);
	/*pFont->printf(300,90,HGETEXT_LEFT, "Helpers Exploring %i", pGameData->HelpersExploring);
	pFont->printf(300,110,HGETEXT_LEFT, "Helpers available for exploring %i", pGameData->HelpersAvailable );*/
	pFont->printf(m_timeTextPos.x, m_timeTextPos.y, HGETEXT_LEFT, "Weeks exploring: %.0f", m_timeAssigned); 
	pFont->printf(m_helperExploreTextPos.x, m_helperExploreTextPos.y, HGETEXT_LEFT, "Workers to send exploring: %i", m_preHelperChoice);
	pFont->printf(470,m_helperExploreTextPos.y,HGETEXT_LEFT, "Helpers Exploring %i", pGameData->HelpersExploring);
	pFont->printf(470,m_helperExploreTextPos.y+ 20,HGETEXT_LEFT, "Helpers available for exploring %i", pGameData->HelpersAvailable );
	
	pFont->printf(470,m_helperExploreTextPos.y+ 40,HGETEXT_LEFT, "Candy canes required %.0f",  (m_preHelperChoice * m_timeAssigned) / m_candyCaneModifier );
	pFont->printf(470,m_helperExploreTextPos.y+ 60,HGETEXT_LEFT, "Acres gained %.1f", pGameData->ExploringCoeff * m_preHelperChoice * m_timeAssigned);
	
	pFont->SetColor( ARGB(255,90,100,90));


	
	for(int i = 0; i < pGameData->MaxExpeditions; i++)
	{
		if(pGameData->Expeditions[i] > 0)
			pFont->printf(160, 520 + (i * textSpace), HGETEXT_LEFT, "Expedition team: returning with %.1f acres in %.0f week(s) ",  pGameData->ExploringCoeff * pGameData->Expeditions[i] * pGameData->TimeInExpedition[i],(pGameData->TimeForExpeditionsToReturn[i] / 60) );
		else
			pFont->printf(160, 520 + (i * textSpace), HGETEXT_LEFT, "Empty spot for exploring");
	}

	pFont->SetScale(1);
	pFont->SetColor( ARGB(255,255,255,255));

	hGui->Render();

}

void ExploreScreen::Update(float fDeltaTime)
{

	guiId = hGui->Update(fDeltaTime);

	if(guiId != 0)
	{
		switch (guiId)
		{
		case 1:
			if(pGameData->HelpersAvailable > 0 && pGameData->CandyCanes >  (m_preHelperChoice * m_timeAssigned) / m_candyCaneModifier)
			{
				pGameData->HelpersAvailable--;
				m_preHelperChoice++;
				g_pAudioManager->PlayEffect("huh1");
			}
			break;
		case 2:
			if(m_preHelperChoice > 0)
			{
				pGameData->HelpersAvailable++;
				m_preHelperChoice--;
				g_pAudioManager->PlayEffect("huh2");

			}
			break;

		case 3:
			if(pGameData->CandyCanes >  (m_preHelperChoice * m_timeAssigned) / m_candyCaneModifier && m_preHelperChoice > 0)
			{
				m_timeAssigned++;
				g_pAudioManager->PlayEffect("boing");

			}
			break;

		case 4: 
			if(m_timeAssigned > 0)
				m_timeAssigned--;
				g_pAudioManager->PlayEffect("boing");

			break;

		case 5:
			if(m_preHelperChoice > 0 && m_timeAssigned >= 1.0)
			{

				for(int i = 0; i < pGameData->MaxExpeditions; i++)
				{
					if(pGameData->Expeditions[i] <= 0)
					{
						pGameData->Expeditions[i] = m_preHelperChoice;
						pGameData->TimeForExpeditionsToReturn[i] = m_timeAssigned * 60;
						pGameData->TimeInExpedition[i] = m_timeAssigned;
						pGameData->CandyCanes -=  (m_preHelperChoice * m_timeAssigned) / m_candyCaneModifier;
						
						m_timeAssigned = 0.0f;
						//pGameData->HelpersAvailable -= m_preHelperChoice;
						pGameData->HelpersExploring += m_preHelperChoice;
						g_pAudioManager->PlayEffect("march");
						break;
					}
				}

				m_preHelperChoice = 0;

			}
			break;
		default:
			break;
		}

	}
}